
const { ccclass, property, menu } = cc._decorator;

const DistanceType = cc.Enum({
    custom: 0,
    width: 1,
    height: 2,
})

/**
 * 反向动力学关节约束
 */
@ccclass
@menu('cccframework/IKConstraint')
export class IKConstraint extends cc.Component {

    @property({ tooltip: '限制角度' })
    angleLimit: cc.Vec2 = cc.v2(0, 360);
    @property({ type: DistanceType, tooltip: '距离类型' })
    distanceType: number = DistanceType.height;
    @property({ type: cc.Float, tooltip: '限制角度' })
    distance: number = 50;

    @property({ type: cc.Float, min: 0, max: 1, step: 0.05, tooltip: '长度百分比' })
    percent: number = 1;

    onLoad() {
        switch (this.distanceType) {
            case DistanceType.custom:
                if (typeof this.distance != 'number') {
                    this.distance = this.distance
                }
                break;
            case DistanceType.width:
                this.distance = this.node.width * this.percent;
                break;
            case DistanceType.height:
                this.distance = this.node.height * this.percent;
                break;

        }
    }
}
